% --------------------------------------------------------
% transformation from rotating frame to P1 centered inertial frame
%
% Copyright(C) 2015/06/30 by Chen Zhang, 
% School of Astronautics, Beihang University
% chenzhang.buaa@gmail.com
% --------------------------------------------------------
function [XX, TT] = rot2ini(xx, tt, mu)
% inizialize output
TT = tt ; XX = xx ;
xx (:,1) = xx (:,1) + mu ; % place the origin at P1
n = length(tt);
for i = 1 : n
    cost = cos(tt(i)) ; sint = sin(tt(i)) ;
    R = [ cost -sint 0 ;
          sint  cost 0 ;
           0     0   1 ] ;
    Rdot = [ -sint -cost 0 ;
              cost -sint 0 ;
              0     0    0 ] ;
    rr = R * xx(i,1:3)' ;
    vv = (R * xx(i,4:6)' + Rdot * xx(i,1:3)') ;
    XX(i,1:6) = [rr' vv'] ;
end
end
% --------------------------------------------------------